package com.ttl.bc.ap.action;


import java.util.HashSet;
import java.util.List;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.actions.DispatchAction;


import com.ttl.bc.ap.bean.BCAPInvoiceSub;
import com.ttl.bc.ap.db.BCAPInvoiceSubDAO;

import com.ttl.bc.stock.request2.bean.BCStkIssue2;
import com.ttl.bc.stock.request2.bean.BCStkIssueSub2;
import com.ttl.bc.stock.request2.db.BCStkIssue2DAO;

public class BCAPInvoiceSubAction extends DispatchAction {
	
	@SuppressWarnings("unchecked")
	public ActionForward find(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
			throws Exception {
		
				
		BCStkIssue2DAO dao1 = new BCStkIssue2DAO();
		

//##################################
		BCStkIssue2 main = new BCStkIssue2();
		
		HashSet set = new HashSet();
for(int i=0; i<5; i++) {		
		BCStkIssueSub2 sub21 = new BCStkIssueSub2();
		sub21.setBcStkIssue2(main);
		sub21.setDepartCode("600");
		sub21.setIssueType("01");
		sub21.setItemCode("itemCode"+Math.round(Math.random()*10000));
		sub21.setItemName("itemName - >"+Math.round(Math.random()*10000));
		sub21.setQty(10f);
		sub21.setRemainQty(10f);
		sub21.setWhCode("10");
		
		sub21.setShelfCode("10");
//		BCShelfBean shelf = new BCShelfBean();
//		shelf.setCode("10");
//		sub21.setBcShelf(shelf);
		
		
		sub21.setUnitCode("001");
//		BCItemUnitBean itemU = new BCItemUnitBean();
//		itemU.setCode("001");
//		sub21.setBcitemUnit(itemU);
		
		
		set.add(sub21);
}		
		main.setCreatorCode("sa");
		main.setDepartCode("600");
		main.setDocNo("F1-GA->"+Math.round(Math.random()*10000));
		main.setIsCompleteSave(1);
		main.setIssueType("01");
		main.setPersonCode("GA-00267");
		//main.setProjectCode("427106");
		
		main.setBcStkIssueSub2s(set);
		dao1.add(main);
		
//		
//		Employee emp1 = new Employee();
//		emp1.setEmployeeId(1001);
//		emp1.setEmployeeName("test1");
//
//		Employee emp2 = new Employee();
//		emp2.setEmployeeId(1002);
//		emp2.setEmployeeName("test2");
//		Employee emp3 = new Employee();
//		emp3.setEmployeeId(1003);
//		emp3.setEmployeeName("test3");
//
//		Set emps = new HashSet();
//		emps.add(emp1);
//		emps.add(emp2);
//		emps.add(emp3);
//		Dept dept = new Dept();
//		dept.setDeptId(1001);
//		dept.setDeptName("test dept1");
//		dept.setEmployees(emps);
//		
//		dao1.add(dept);						
				
		System.out.println("############# ok!");
		
		long startTime = System.currentTimeMillis();
		
		//System.out.println("############ find();");
		DynaActionForm dynaForm = (DynaActionForm)form;
		String findData = dynaForm.getString("findData");
		//System.out.println("############ findData  :" + findData);
		BCAPInvoiceSubDAO dao = new BCAPInvoiceSubDAO();		
		
		List<BCAPInvoiceSub> result = dao.find(findData);
		//System.out.println("#########  result size=  "+result.size()+"  #########");
		
		long endTime = System.currentTimeMillis();
		double resultTime = (endTime-startTime)/1000.0;
		
		request.getSession().setAttribute("bcapinvData", result);
		request.getSession().setAttribute("resultTime", resultTime);
		
		return mapping.findForward("findSuccess");
	}
}
